﻿@using KPIS.GERP.SERVICE.Model
@model KPIS.GERP.MVC.Models.LogOnModel

@{
    ViewBag.Title = "Log in";
}

<br /><br /><br />

<div class="login">
    
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
    <fieldset>
        <legend>กรอกข้อมูลเพื่อเข้าระบบ</legend>
        
        @Html.ValidationSummary(true, "ไม่สามารถเข้าระบบได้ แก้ไขข้อมูลใหม่แล้วลองอีกครั้ง")
        <br />
        <br />
        <div class="editor-label">
            @Html.LabelFor(m => m.UserName)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(m => m.UserName)
            @Html.ValidationMessageFor(m => m.UserName)
        </div>
        <br />

        <div class="editor-label">
            @Html.LabelFor(m => m.Password)
        </div>
        <div class="editor-field">
            @Html.PasswordFor(m => m.Password)
            @Html.ValidationMessageFor(m => m.Password)
        </div>

        <br />
        <br />

        <input type="submit" value="เข้าระบบ" />
        @*<div class="editor-label">
            @Html.CheckBoxFor(m => m.RememberMe)
            @Html.LabelFor(m => m.RememberMe)
        </div>*@
    </fieldset>
    
}

</div>

@{
    List<sys_sc_users> users = null;
    using (var db = new GERPContext())
    {
        users = (from u in db.sys_sc_users select u).ToList();
        
        @Html.Raw("<div style='float: left;'>")

            foreach (var user in users)
            {
                var usercode = user.user_code;
                var userpw = user.user_password;
                var fullname = user.hrm_ps_employees == null ? "-" : user.hrm_ps_employees.full_name;
                <text>
                    @Html.Raw("<div class='inline'>")
                        @using (Html.BeginForm())
                        {
                            @Html.AntiForgeryToken()
                            @Html.HiddenFor(m => m.UserName, new {@Value =  usercode}) 
                            @Html.HiddenFor(m => m.Password, new {@Value =  userpw})
                            <input type="submit" value="@fullname" />
                        }
                    @Html.Raw("</div>")
                </text>
            }
        @Html.Raw("</div>")
    }
}

<style type="text/css">
div.inline { float:left; }
.clearBoth { clear:both; }
</style>